
import 'package:flutter/material.dart';
import 'package:flutter_eve_plugin/constants/constant.dart';
import 'package:flutter_eve_plugin/model/base_res.dart';
import 'package:flutter_eve_plugin/model/health/user_info.dart';
import 'package:flutter_eve_plugin/model/ye_xiu/login/bind_result.dart';
import 'package:flutter_eve_plugin/pages/ye_xiu/login/constant.dart';
import 'package:flutter_eve_plugin/plugin/main.dart';
import 'package:flutter_eve_plugin/route/main.dart';
import 'package:flutter_eve_plugin/store/base_action.dart';
import 'package:redux/redux.dart';
import 'package:redux_thunk/redux_thunk.dart';

areaCode(Store store, String areaCode) {
  store.dispatch(BaseAction(type: YX_AREA_CODE, data: areaCode));
}

inputPhone(Store store, String phone) {
  store.dispatch(BaseAction(type: YX_PHONE, data: phone));
}

inputCode(Store store, String code) {
  store.dispatch(BaseAction(type: YX_CODE, data: code));
}

inputNickName(Store store, String nickName) {
  store.dispatch(BaseAction(type: YX_NICK_NAME, data: nickName));
}

inputBirthday(Store store, int birthday) {
  store.dispatch(BaseAction(type: YX_BIRTHDAY, data: birthday));
}

inputSex(Store store, int sex) {
  store.dispatch(BaseAction(type: YX_SEX, data: sex));
}

inputWifiName(Store store, String wifiName) {
  store.dispatch(BaseAction(type: YX_WIFI_NAME, data: wifiName));
}

inputWifiPass(Store store, String wifiPass) {
  store.dispatch(BaseAction(type: YX_WIFI_PASS, data: wifiPass));
}

bindRes(Store store, BindResultModel model) {
  if (model == null) return;
  store.dispatch(BaseAction(type: YX_BIND_RES, data: model));
}

ThunkAction birthdayConfirm(BuildContext context, UserInfoModelReq req) {
  return (Store store) async {
    PluginEve.sendMessage(PluginConstant.httpYXEditUserInfo,
            param: req, httpType: HttpType.POST)
        .then((data) =>
            Navigator.pushNamed(context, RouteConstant.LoginSelectMachinePage));
  };
}

ThunkAction appDebug() {
  return (Store store) async {
    PluginEve.sendMessage(PluginConstant.actionAppDebug, httpType: HttpType.POST);
  };
}

goC2HomeNative() {
  PluginEve.sendMessage(PluginConstant.actionAppC2Home, httpType: HttpType.POST);
}

goYXHomeNative() {
  PluginEve.sendMessage(PluginConstant.actionAppYXHome, httpType: HttpType.POST);
}

ThunkAction switchIP(String ip) {
  return (Store store) async {
    var req = {'idol': ''};
    if (ip == '琥珀') {
      req = {'idol': 'C2'};
    } else if (ip == '叶修') {
      req = {'idol': 'YEXIU'};
    }
    BaseRes res = await PluginEve.sendMessage(PluginConstant.httpYXSwitchIP,
        param: req, httpType: HttpType.POST);
    if (res.code == 0) {
      if (ip == '琥珀') {
        goC2HomeNative();
      } else if (ip == '叶修') {
        goYXHomeNative();
      }
    }
  };
}
